const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');

/**
 * 解析路径
 * @param {*} p __dirname下的文件夹或者文件 
 */
const resolve = (p) => path.resolve(__dirname, p);

module.exports = {
    mode: 'development',
    entry: resolve('src/index.js'),
    output: {
        path: resolve('dist'),
        filename: 'main.js'
    },
    devtool: 'source-map',
    module: {
        // 匹配规则
        rules: [
            {
                test: /\.jsx?$/,
                use: 'babel-loader'
            }
        ]
    },
    // 插件
    plugins: [
        new HtmlWebpackPlugin({
            template: resolve('public/index.html'),
            filename: 'index.html'
        })
    ],
    // 开发服务器
    resolve: {
        extensions: ['.js', '.jsx'],
        alias: {
            '@': resolve('src')
        }
    },
    devServer: {
        port: 3000,
        compress: true,
        hot: true
    }
}